// import qs from "qs";
// import wx from "@/sdk/jweixin";
// import { wxInitApi } from "@/api/base";
// import CacheUtils from "./CacheUtils";

export function login(params = {}) {
  params.appid = params.appid ?? import.meta.env.VITE_APP_APPID;
  params.redirect_uri = params.redirect_uri ?? location.href;
  params.response_type = params.response_type || "code";
  // 显性授权
  // params.scope = params.scope || "snsapi_userinfo";
  params.scope = params.scope || "snsapi_base";
  console.log(params);

  // 手动构建查询字符串
  const queryString = Object.keys(params)
      .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
      .join('&');
  let url = `https://open.weixin.qq.com/connect/oauth2/authorize?${queryString}#wechat_redirect`;
 // let url = `https://open.weixin.qq.com/connect/oauth2/authorize?${qs.stringify(params,)}&#wechat_redirect`;
  window.location.href = url;
}

// export async function wxInit(jsApiList, openTagList) {
//   let data = await wxInitApi(CacheUtils.getCache("url") || location.href);
//   return new Promise((resolve) => {
//     wx.config({
//       debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印
//       ...data,
//       jsApiList, // 必填，需要使用的JS接口列表
//       openTagList,
//     });
//     wx.ready(() => {
//       resolve();
//     });
//   });
// }
